< previous page page_174 next page >

Page 174
Although designing your program's user interface with forms and controls is important, most of the actual work is done with code. By code, I mean the sections of the program where you type statements and functions. You already know that forms can contain code, and you have seen how to access the code "below the surface" of a form's visual interface. As a reminder, consider all the parts of a Visual Basic program that can contain code:
Forms
Code modules
Class modules
User controls
The great thing about Visual Basic is that the language you write code in is both powerful and relatively easy to use. It is a direct descendant of the BASIC programming language, which has been around for many years. BASIC was designed as a language for beginning programmers, hence the name, which is an abbreviation for Beginner's All-Purpose Symbolic Instruction Code.
Don't let the "Basic" part of the name fool you, however. Visual Basic is a far more powerful language than the BASIC you may have already learned. The more recent releases have extended the language far beyond its primitive ancestry. Visual Basic has grown into a robust programming environment that can solve a wide variety of application needs.
This chapter looks at some of the fundamental concepts of programming in Visual Basic: writing program code, working with and formatting information, and so on. Chapter 10, "Controlling the Flow of Your Program Code," continues this discussion by examining how to control your program with loops and conditional statements.
Writing Statements
In the preceding chapter, "Using Variables to Store Information," you learned a little about variables and constants. You know what type of data they can store and how to declare them. But that is just the beginning of working with information in a program. You also need to be able to assign information to variables, manipulate that information, and use the contents of variables in other Visual Basic code.
To perform these tasks, you use code statements. Simply put, a statement is a line of code that makes the computer do something. Here are a few examples of the things you can do with statements:
Statement Type
Example
Assign a value to a variable
sName = "Lauren"
Call a predefined function
MsgBox "Good morning!"
Call your own function
bSuccess = BuildBudgetReport("12/31/99")
Assign object properties
frmMain.Visible = False
Make decisions
If nTideHeight > 1000 then MoveOn

 
< previous page page_174 next page >